<template>
	<view class="goodsList u-skeleton">
		<u-navbar  title="商品" :background="{
			'backgroundColor':'#fff'
		}" :borderBottom="false" class="u-skeleton-rect"></u-navbar>
		<view class="title-slect u-skeleton-rect">
			<view class="left">综合排序</view>
			<view class="right">
				<view class="title" :style="{
					'font-weight':type == 1 ? 'bold' : ''
				}" @click="select(1)">热门</view>
				<view class="title" :style="{
					'font-weight':type == 2 ? 'bold' : ''
				}" @click="select(2)">最新</view>
				<view class="title" :style="{
					'font-weight':type == 3 ? 'bold' : ''
				}" @click="select(3)">价格</view>
				<view class="icon-box">
					<u-icon name="arrow-up-fill" :color="current == 'top' ? '#000' : '#909399' " size="20" @click="selectTop('top',3)"></u-icon>
					<u-icon name="arrow-down-fill" :color="current == 'bottom' ? '#000' : '#909399' " size="20" @click="selectTop('bottom',4)"></u-icon>
				</view>
			</view>
		</view>
		<div class="box-scroll">
			<diy-scorll  :Empty='goodsList.length ? false : true' :status = 'status' @scrolltolower='getgoods' @refresherrefresh='refresherrefresh'>
				<diy-goods :list='goodsList' @getgoods='getgoods'></diy-goods>
			</diy-scorll>
		</div>
		<u-skeleton :loading="loding" :animation="true" bgColor="#FFF"></u-skeleton>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				loding: true,
				current:'top',
				//加载配置
				page:{
					page:1,
					page_size:8,
				},
				//商品列表
				goodsList:[],
				//判断刷新出来滚动出现的文字
				status:'loadmore',
				//商品分类
				goods_type:0,
				//排序类型
				type:1
			}
		},
		onLoad(option) {
			if(option.id){
				this.id = option.id;
			} else this.loding = true;
		},
		methods:{
			//切换选择
			select(type){
				this.type = type;
				this.refresherrefresh();
			},
			//价格切换选择
			selectTop(current,type){
				this.current = current;
				this.type = type;
				this.refresherrefresh();
			},
			// 下拉双薪
			refresherrefresh(callback){
				this.page = {
					page:1,
					page_size:8,
				},
				this.getgoods(callback);
			},
			// 或许商品列表
			getgoods(callback){
				this.$http.asyncSendrequest({
					url:'/goods/goodsList',
					data:{
						type:this.type,
						goods_type:this.id,
						...this.page
					},
					success:res=>{
						if(res.code == '0') {
							if(this.page.page == 1) this.goodsList = [];
							if(res.data.length){
								this.goodsList = this.goodsList.concat(res.data);
								this.page.page += 1;
							} else {
								//下面加载的文字
								this.status = 'nomore';
							}
							if(typeof callback == 'function') callback();
							this.loding = false;
						}
					}
				})
			},
		}
		
	}
</script>

<style lang="scss" scoped>
	.goodsList{
		width: 100%;
		height: 100vh;
		.title-slect{
			display: flex;
			align-items: center;
			justify-content: space-between;
			background: #fff;
			padding:36rpx;
			box-sizing: border-box;
			margin-bottom: 26rpx;
			.left{
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
			}
			.right{
				display: flex;
				align-items: center;
				.title{
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
					margin-left: 54rpx;
				}
				.icon-box{
					display: flex;
					align-items: center;
					justify-content: center;
					flex-direction: column;
					margin-left: 10rpx;
					.icon{
						
					}
				}
			}
		}
		.box-scroll{
			width: 100%;
			height: calc(100vh - 240rpx);
		}
	}
</style>